home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5352 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ Gurus! Is it correct?
  5. Date: Sun, 04 Feb 1996 00:59:16 GMT
  6. Organization: Netcom
  7. Message-ID: <311403bf.169980736@nntp.ix.netcom.com>
  8. References: <4eqvtg$cg5@israel-info.datasrv.co.il> <4etnju$6gn@rolaids.frco.com> <4f0n8s$a3b@news2.ios.com>
  9. NNTP-Posting-Host: ix-dc15-14.ix.netcom.com
  10. X-NETCOM-Date: Sat Feb 03  4:58:57 PM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. vlad@gramercy.ios.com (Vlastimil Adamovsky) wrote:
  14.  
  15. > Jadam@tcmail.frco.com (Jim Adam) wrote:
  16. > >In article <4eqvtg$cg5@israel-info.datasrv.co.il>, dmitry@enigma.co.il 
  17. > >says...
  18. > >>Is next code is correct from point of view of pure C++ ?
  19. > >>class A
  20. > >>{
  21. > >>};
  22. > >>class B
  23. > >>{
  24. > >>};
  25. > >>class C : public A, public B
  26. > >>{
  27. > >>};
  28. > >>A* pA = new C;
  29. > >>B* pB = new C;
  30. > >>delete pA;
  31. > >>delete pB;
  32. > >==========================
  33. > >This is correct.  However, to ensure the destructor for class
  34. > >C gets called correctly, class A and B both need virtual 
  35. > >destructors.
  36. > >E.g., 
  37. > >  class A
  38. > >  {
  39. > >    public:
  40. > >      virtual ~A();
  41. > >  };
  42. > >And likewise for class B.   
  43. > >Jim
  44. > I don't think the virtual destructor is necessary in this specific
  45. > case where you have no added data in subclasses. 
  46.  
  47. Why do you think having data has anything to do with it?  From draft
  48. 5.3.5:
  49.  
  50.     In the first alternative (delete object), if the static type
  51.     of the operand is different from its dynamic type, the static
  52.     type shall be a base  class of the operand's dynamic type
  53.     and the static type shall have a virtual destructor or the
  54.     behavior is undefined.
  55.  
  56.  
  57. Michael M Rubenstein
  58.